package com.lims.landInfo.dao;

import static cn.org.rapid_framework.util.ObjectUtils.*;
import org.springframework.stereotype.Repository;

import javacommon.base.*;

import cn.org.rapid_framework.page.*;

import com.lims.landInfo.model.*;
import com.lims.landInfo.vo.query.*;

/**
 * @author zzh
 * @version 1.0
 * @since 1.0
 */@Repository @SuppressWarnings("unchecked")
public class LawsuitDao extends BaseHibernateDao<Lawsuit,java.lang.String>{
	
	public Class getEntityClass() {
		return Lawsuit.class;
	}
	
	public Page findPage(LawsuitQuery query) {
        //XsqlBuilder syntax,please see http://code.google.com/p/rapid-xsqlbuilder
        // [column]为字符串拼接, {column}为使用占位符. [column]为使用字符串拼接,如username='[username]',偷懒时可以使用字符串拼接 
        // [column] 为PageRequest的属性
		String sql = "select t from Lawsuit t where 1=1 "
			  	+ "/~ and t.sno = {sno} ~/"
			  	+ "/~ and t.landno = {landno} ~/"
			  	+ "/~ and t.complainant = {complainant} ~/"
			  	+ "/~ and t.cause = {cause} ~/"
			  	+ "/~ and t.phase = {phase} ~/"
				+ "/~ and t.lawsuitDate >= {lawsuitDateBegin} ~/"
				+ "/~ and t.lawsuitDate <= {lawsuitDateEnd} ~/"
			  	+ "/~ and t.changeType = {changeType} ~/"
			  	+ "/~ and t.oldno = {oldno} ~/"
			  	+ "/~ and t.oldContent = {oldContent} ~/"
			  	+ "/~ and t.describe = {describe} ~/"
				+ "/~ and t.landDate >= {landDateBegin} ~/"
				+ "/~ and t.landDate <= {landDateEnd} ~/"
				+ "/~ and t.createDate >= {createDateBegin} ~/"
				+ "/~ and t.createDate <= {createDateEnd} ~/"
				+ "/~ order by [sortColumns] ~/";

        //生成sql2的原因是为了不喜欢使用xsqlbuilder的同学，请修改生成器模板，删除本段的生成
        StringBuilder sql2 = new StringBuilder("select t from Lawsuit t where 1=1 ");
        if(isNotEmpty(query.getObjid())) {
            sql2.append(" and  t.objid = :objid ");
        }
        if(isNotEmpty(query.getSno())) {
            sql2.append(" and  t.sno = :sno ");
        }
        if(isNotEmpty(query.getLandno())) {
            sql2.append(" and  t.landno = :landno ");
        }
        if(isNotEmpty(query.getComplainant())) {
            sql2.append(" and  t.complainant = :complainant ");
        }
        if(isNotEmpty(query.getCause())) {
            sql2.append(" and  t.cause = :cause ");
        }
        if(isNotEmpty(query.getPhase())) {
            sql2.append(" and  t.phase = :phase ");
        }
        if(isNotEmpty(query.getLawsuitDateBegin())) {
            sql2.append(" and  t.lawsuitDate >= :lawsuitDateBegin ");
        }
        if(isNotEmpty(query.getLawsuitDateEnd())) {
            sql2.append(" and  t.lawsuitDate <= :lawsuitDateEnd ");
        }
        if(isNotEmpty(query.getChangeType())) {
            sql2.append(" and  t.changeType = :changeType ");
        }
        if(isNotEmpty(query.getOldno())) {
            sql2.append(" and  t.oldno = :oldno ");
        }
        if(isNotEmpty(query.getOldContent())) {
            sql2.append(" and  t.oldContent = :oldContent ");
        }
        if(isNotEmpty(query.getDescribe())) {
            sql2.append(" and  t.describe = :describe ");
        }
        if(isNotEmpty(query.getLandDateBegin())) {
            sql2.append(" and  t.landDate >= :landDateBegin ");
        }
        if(isNotEmpty(query.getLandDateEnd())) {
            sql2.append(" and  t.landDate <= :landDateEnd ");
        }
        if(isNotEmpty(query.getCreateDateBegin())) {
            sql2.append(" and  t.createDate >= :createDateBegin ");
        }
        if(isNotEmpty(query.getCreateDateEnd())) {
            sql2.append(" and  t.createDate <= :createDateEnd ");
        }
        if(isNotEmpty(query.getSortColumns())) {
            sql2.append(" order by :sortColumns ");
        }	
        
		return pageQuery(sql,query);
	}
	

}
